package com.ccys.db.mapper;

import com.ccys.db.dto.consultation.BookingQueueDTO;
import com.ccys.db.entity.TblBookingQueue;
import com.ccys.db.vo.consultation.BookingQueueWebVO;
import com.ccys.db.vo.consultation.CountBookingNumWebVO;
import com.ccys.db.vo.doctor.pendingToConsult.GetNumOfPatientOnQueueVo;
import org.apache.ibatis.annotations.Param;
import tk.mybatis.mapper.common.Mapper;
import tk.mybatis.mapper.common.MySqlMapper;

import java.util.List;

/**
 * Created by Mybatis Generator on 2023/12/29
 */
public interface TblBookingQueueMapper extends Mapper<TblBookingQueue>, MySqlMapper<TblBookingQueue> {

    /**
     * @description 查询问诊对列列表
     * @date 2024/1/2
     * @author cloud fly
     */
    List<BookingQueueWebVO> listObjectsCms(BookingQueueDTO dto);

    /**
     * @description 统计对列国家与科室的问诊排队数量
     * @date 2024/1/2
     * @author cloud fly
     */
    List<CountBookingNumWebVO> countBookingNum(BookingQueueDTO dto);

    /**
     * @description 向后移动对列
     * @date 2024/1/2
     * @author cloud fly
     */
    int updateBackwardMoveQueue(@Param("queueNo") Integer queueNo, @Param("queueNo1") Integer queueNo1);

    /**
     * @description 向前移动对列
     * @date 2024/1/2
     * @author cloud fly
     */
    int updateForwardMoveQueue(@Param("queueNo") Integer queueNo, @Param("queueNo1") Integer queueNo1);

    Integer findCountByDoctorIdAndByNotBookingId(@Param("doctorId") String doctorId, @Param("bookingId") String bookingId);

    String findCurrentBookingIdByDoctorId(@Param("doctorId") String doctorId);

    void updateQueueNoNullByBookingId(@Param("bookingId") String bookingId);

    TblBookingQueue findOneByBookingIdAndByStatus(@Param("bookingId") String bookingId);

    /**
     * 根据bookingId真删
     *
     * @param bookingId bookingId
     */
    void deleteByBookingId(@Param("bookingId") String bookingId);

    void updatePositionNoMinusOneByDoctorId(@Param("doctorId") String doctorId, @Param("positionNo") Integer positionNo);

    void updateQueueNoSetNullByBookingId(@Param("bookingId") String bookingId);

    GetNumOfPatientOnQueueVo getNumOfPatientOnQueue(String doctorId, Integer panelType);

    GetNumOfPatientOnQueueVo getNumOfPatientOnQueueNoSelectedDoctor(String doctorId);

    /**
     * 根据分组以及国家ID以及identification将队列queueNo全部减一
     *
     * @param groupId        groupId
     * @param countryId      countryId
     * @param identification identification
     */
    void updateQueueNoByGroupIdAndByCountryIdAndByIdentification(@Param("groupId") String groupId, @Param("countryId") String countryId, @Param("identification") String identification);


    TblBookingQueue findByBookingId(@Param("bookingId") String bookingId);

    /**
     * 查询这个分组下的国家的服务的医生的最大队列展示位置的值，如果为null则返回0
     *
     * @param groupId groupId
     * @param doctorId doctorId
     * @param countryId countryId
     * @param identification identification
     * @return
     */
    Integer findMaxPositionNo(@Param("groupId") String groupId,@Param("doctorId") String doctorId,@Param("countryId") String countryId,@Param("identification") String identification);

    void updateQueueNoByBookingIdAndByMaxQueueNo(@Param("bookingId") String bookingId,@Param("maxQueueNo") Integer maxQueueNo);

    /**
     * 函数：fn_Get_Num_Patient_InFrontOf_For_SP
     *
     * @param doctorId doctorId
     * @param bookingId bookingId
     * @param groupId groupId
     * @param countryId countryId
     * @param identification identification
     * @param isMoveLast isMoveLast
     * @return
     */
    Integer fnGetNumPatientInFrontOfForSP(@Param("doctorId") String doctorId,@Param("bookingId") String bookingId,
                                          @Param("groupId") String groupId,@Param("countryId") String countryId,
                                          @Param("identification") String identification,@Param("isMoveLast") Integer isMoveLast);
}
